import functools
import requests
import asyncio
from concurrent.futures import ThreadPoolExecutor
from threading import Lock
from async_threading import async_timed

counter_lock = Lock()
counter = 0


def get_status_code(url):
    global counter
    response = requests.get(url)
    with counter_lock:
        counter += 1
    return response.status_code


async def reporter(request_count):
    while counter < request_count:
        print(f"finished {counter} / {request_count} requests")
        await asyncio.sleep(.1)


@async_timed()
async def main():
    loop = asyncio.get_running_loop()

    with ThreadPoolExecutor() as executor:
        request_count = 200
        urls = ["http://www.baidu.com" for _ in range(request_count)]
        reporter_task = asyncio.create_task(reporter(request_count))
        tasks = [loop.run_in_executor(executor, functools.partial(get_status_code, url)) for url in urls]
        results = await asyncio.gather(*tasks)
        await reporter_task
        print(results)

asyncio.run(main())